<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">

    <ui:define name="content">
        <p:panel header="Cadastro de Animais">
            <h:form id="frmGrid">  

                <p:growl id="msgs" showDetail="true"/>  
                <p:panelGrid columns="3">
                    <p:column>
                        Escolha uma Recinto:
                    </p:column>
                    <p:column>
                        <p:selectOneMenu id="cmbRecintos" value="#{animalMB.PIdtRecinto}" effect="fold" editable="false">
                            <f:selectItem itemLabel="Todos os Recintos" itemValue="0" /> 
                            <f:selectItems value="#{animalMB.tdRecintos}" var="recinto" 
                                           itemLabel="#{recinto.nmeRecinto}" itemValue="#{recinto.idtRecinto}"/>  
                        </p:selectOneMenu> 
                    </p:column>
                    <p:column>
                        <p:commandButton value="Buscar" actionListener="#{animalMB.filtrar()}" update=":frmGrid:msgs, :frmGrid:dtbAnimals" icon="ui-icon-search"/>
                    </p:column>
                </p:panelGrid>

                <p:dataTable id="dtbAnimals" var="animal" value="#{animalMB.tbAnimals}" tableStyle="width:auto;" paginator="true" rows="5">  

                    <p:column headerText="Identificador" style="width:100px">  
                        <h:outputText value="#{animal.idtAnimal}" />  
                    </p:column>  

                    <p:column headerText="Nome do Recinto" style="width:100px">  
                        <h:outputText value="#{animal.tdRecinto.nmeRecinto}" />  
                    </p:column>  

                    <p:column headerText="Nome" style="width:300px">  
                        <h:outputText value="#{animal.nmeAnimal}" />  
                    </p:column>  

                    <p:column headerText="Status do Animal" style="width:300px">  
                        <h:outputText value="#{animal.stsAnimal}" />  
                    </p:column> 

                    <p:column headerText="Operacao" style="width:200px">  
                        <p:panelGrid columns="2">  
                            <p:column>
                                <p:commandButton id="btnEditar" update=":frmForm:pngEditar" oncomplete="dlgAnimalView.show()" icon="ui-icon-pencil" value="Editar">  
                                    <f:setPropertyActionListener value="#{animal}" target="#{animalMB.selAnimal}" />  
                                </p:commandButton>  
                            </p:column>
                            <p:column>
                                <p:commandButton id="btnExcluir" update=":frmExcluir:dlgConfExclusao" oncomplete="dlgConfExclusaoView.show()" icon="ui-icon-trash" value="Excluir">  
                                    <f:setPropertyActionListener value="#{animal}" target="#{animalMB.selAnimal}" />  
                                </p:commandButton>  
                            </p:column>
                        </p:panelGrid>  
                    </p:column>  

                </p:dataTable>  

                <p:commandButton id="btnNovo" update=":frmForm:pngEditar" actionListener="#{animalMB.novo}" oncomplete="dlgAnimalView.show()" icon="ui-icon-star" value="Novo" ajax="true"/> 
            </h:form> 

            <p:dialog header="Editar" widgetVar="dlgAnimalView" resizable="false" id="dlgAnimal"  
                      showEffect="fade" hideEffect="explode" modal="true">  
                <h:form id="frmForm">
                    <p:panelGrid id="pngEditar" columns="2" style="margin:0 auto;">  
                        <p:column>
                            <h:outputText value="Identificador:" />  
                        </p:column>
                        <p:column>
                            <p:inputText id="idtAnimal" value="#{animalMB.selAnimal.idtAnimal}" disabled="true" size="5"/>  
                        </p:column>
                        <p:column>
                            <h:outputText value="Recinto:" />  
                        </p:column>
                        <p:column>
                            <p:selectOneMenu id="cmbRecintos" value="#{animalMB.PIdtRecinto}" effect="fold" editable="false">
                                <f:selectItem itemLabel="#{animalMB.selAnimal.tdRecinto.nmeRecinto}" itemValue="0" /> 
                                <f:selectItems value="#{animalMB.tdRecintos}" var="recinto" 
                                               itemLabel="#{recinto.nmeRecinto}" itemValue="#{recinto.idtRecinto}"/>  
                                <f:validateLongRange minimum="1"/>
                            </p:selectOneMenu> 
                        </p:column>
                        <p:column>
                            <h:outputText value="Nome:" />  
                        </p:column>
                        <p:column>
                            <h:inputText id="nmeAnimal" value="#{animalMB.selAnimal.nmeAnimal}" size="30" required="true" requiredMessage="Nome do Animal e Obrigatorio"/>  
                        </p:column>
                        <p:column>
                            <h:outputText value="Status:" />  
                        </p:column>
                        <p:column>
                            <h:inputText id="stsAnimal" value="#{animalMB.selAnimal.stsAnimal}" size="30" required="true" requiredMessage="Status do Animal e Obrigatorio"/>  
                        </p:column>
                        <p:column>
                            <h:outputText value="Peso:" />  
                        </p:column>
                        <p:column>
                            <h:inputText id="psoAnimal" value="#{animalMB.selAnimal.psoAnimal}" size="30" required="true" requiredMessage="Peso do Animal e Obrigatorio"/>  
                        </p:column>
                         <p:column>
                            <h:outputText value="RG:" />  
                        </p:column>
                        <p:column>
                            <h:inputText id="rgAnimal" value="#{animalMB.selAnimal.rgAnimal}" size="30" required="true" requiredMessage="Rg do Animal e Obrigatorio"/>  
                        </p:column>
                        
                        
                        <p:column>
                            <p:commandButton id="btnSalvar" actionListener="#{animalMB.salvar}" update=":frmForm:pngEditar, :frmGrid:dtbAnimals, :frmGrid:msgs" icon="ui-icon-disk" value="Salvar" ajax="true"/>  
                        </p:column>
                        <p:column>
                            <p:commandButton id="btnFechar" value="Fechar" icon="ui-icon-close" onclick="dlgAnimalView.hide()"/>  
                        </p:column>
                    </p:panelGrid>  
                </h:form>
            </p:dialog>  

            <h:form id="frmExcluir">
                <p:confirmDialog id="dlgConfExclusao" message="Tem certeza que deseja excluir (#{animalMB.selAnimal.nmeAnimal})?"  
                                 header="Exclusão de registro" severity="alert" widgetVar="dlgConfExclusaoView">  
                    <p:commandButton id="btnConfirm" value="Sim" update=":frmGrid:dtbAnimals, :frmGrid:msgs" oncomplete="dlgConfExclusaoView.hide()" actionListener="#{animalMB.excluir}" />  
                    <p:commandButton id="btnDecline" value="Não" onclick="dlgConfExclusaoView.hide()" type="button" />   
                </p:confirmDialog> 
            </h:form>

        </p:panel>
    </ui:define>

</ui:composition>
